[release/5.0] Fix handling of \G in Regex.Split/Replace #44985
Merged
+39
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #44975 to release/5.0
/cc @stephentoub
Customer Impact
Broken Replace/Split operations where the regex uses the \G anchor. The \G anchor in a .NET regex says that it should match the ending location of the last match. However, our optimized regex scan loop we use for handling Regex.Replace and Regex.Split wasn’t updating the relevant field to indicate that position; as a result, \G used in Regex.Replace and Regex.Split was failing to match after the first occurrence.
Testing
We didn’t have any tests that exercised \G in replace/splits (only in other operations like Regex.Match). I added several.
Risk
Low. It’s a one-line addition to update a tracking field that's only relevant to the processing of \G anchors.